﻿using System.Windows;
using MyFloridaHouse.libSvOpenDistricts.Dialogs;
namespace MyFloridaHouse.libSvOpenDistricts.ViewModel
{
    public partial class ViewModelBase
    {
        
        public PlanInfoDlg fileNewPlanInfoDlg;

        private bool CmdFileNewCanExecute(object parameter)
        {
            return (!isDialogOpen);
        }

        private void CmdFileNewExecute(object parameter)
        {
            ReserveDialog(CmdFileNew);
            if (districtPlan.districtCount > 0)
            {
                // only need to ask for overwrite confirmation if a plan already exists 
                PlanOverwriteConfirmDlg planOverwriteConfirmDlg = new PlanOverwriteConfirmDlg(OnMemberPropertyChanged, DisplayPanelForDialogs);
                planOverwriteConfirmDlg.Start(CmdFileNewGetPlanFileInfo);
            }
            else
            {
                CmdFileNewGetPlanFileInfo(true);
            }
        }

        private void CmdFileNewGetPlanFileInfo(bool result)
        {
            if (result)
            {
                fileNewPlanInfoDlg = new PlanInfoDlg(OnMemberPropertyChanged, DisplayPanelForDialogs, districtPlanTypes);
                fileNewPlanInfoDlg.Start(CmdFileNewGetPlanFileInfoDone);
            }
            else
            {
                ReleaseDialog(CmdFileNew);
            }
        }

        private void CmdFileNewGetPlanFileInfoDone(bool result)
        {
            if (result)
            {
                DistrictPlanLoadReset(fileNewPlanInfoDlg.planName, fileNewPlanInfoDlg.planDescription, fileNewPlanInfoDlg.planDistrictCount, fileNewPlanInfoDlg.planTypeID, fileNewPlanInfoDlg.planTypeName);
            }
            ReleaseDialog(CmdFileNew);

        }



    }
}
